package com.burgeon.backend.SHOP.controller;

import com.burgeon.backend.SHOP.entity.SignConfig;
import com.burgeon.backend.SHOP.service.SignService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.HashMap;


@RestController
@CrossOrigin
@RequestMapping("shop/sign")
public class SignController extends BaseController {
    @Autowired
    private SignService signService;

    @RequestMapping("insert")
    public ResponseResult<Void> insertSign(HttpSession session) {
        if (session.getAttribute("uid")==null){
            return new ResponseResult<>(NOTLOG);
        }
        String token = session.getAttribute("token").toString();
        String uid = session.getAttribute("uid").toString();
        String openid = session.getAttribute("app_openid").toString();
        String phone = session.getAttribute("phone").toString();

        signService.insertSign(openid,uid,token,phone);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("showSignToday")
    public ResponseResult<HashMap> showSignToday(HttpSession session) {
        String token = session.getAttribute("token").toString();

        String uid = session.getAttribute("uid").toString();
        HashMap data = signService.findSignToday(uid,token);
        return new ResponseResult<HashMap>(SUCCESS,data);
    }

    @RequestMapping("config")
    public ResponseResult<Void> inConfig(String integral,HttpSession session) {
        String token = session.getAttribute("token").toString();
        SignConfig signConfig = new SignConfig();
        signConfig.setIntegral(integral);
        signConfig.setToken(token);
        signService.insertSignCfg(signConfig);

        return new ResponseResult<>(SUCCESS);
    }


}
